#include "paint.h"
#include <QStyle>

Paint::Paint(QWidget *parent) :
     QGraphicsView(parent)
{
    setWindowTitle("Paint");
    setWindowIcon(style()->standardIcon(QStyle::SP_DialogResetButton));
    resize(600,600);
    setFixedSize(600,600);

    scene = new QGraphicsScene();
    scene->setSceneRect(0, 0, 600, 600);

    setScene(scene);
    setRenderHint(QPainter::Antialiasing);
    setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
}

Paint::~Paint()
{
    delete scene;
}

void Paint::mousePressEvent(QMouseEvent *event)
{
    if(event->button() == Qt::LeftButton)
        scene->addEllipse(event->x() - 10,
                   event->y() - 10,
                   20,
                   20,
                   QPen(Qt::NoPen),
                   QBrush(Qt::blue, Qt::SolidPattern));
    else if(event->button() == Qt::RightButton)
        scene->addRect(event->x() - 15,
                event->y() - 15,
                30,
                30,
                QPen(Qt::NoPen),
                QBrush(Qt::red, Qt::SolidPattern));
    else
    {
        QPolygon polygon;
        polygon << event->pos() + QPoint(0,-12)
                << event->pos() + QPoint(13,10)
                << event->pos() + QPoint(-13,10);
        scene->addPolygon(polygon,
                          QPen(Qt::NoPen),
                          QBrush(Qt::green, Qt::SolidPattern));
    }
}
